/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fortest;

import java.io.File;
import java.io.FileOutputStream;
import java.rmi.Naming;
import sharefileinterface.ClientInterface;
import sharefileinterface.FilePart;

/**
 *
 * @author nhancom3d
 */
public class TestRMIClient {
        private static final String HOST = "localhost:2013";
        final public static int PART_SIZE = 1000000;
        private static FileOutputStream fos;

    public static void main(String args[]) {
        try {
            System.out.println("Khoi tao");
            ClientInterface c = (ClientInterface) Naming.lookup("rmi://" + HOST + "/ShareServerOnClient");
            System.out.println("Ket noi thanh cong");
            
            String fileGet = "test.dat";
            System.out.println("File to Save: " + fileGet);
            String currentDirectory = System.getProperty("user.dir");
            String uploaddirectory = currentDirectory + "\\share\\" + fileGet;
            File of = new File(uploaddirectory);
            fos = new FileOutputStream(of);
            
            
            FilePart part1 = c.needFilePart(3, 0);
            fos.write(part1.data, 0, part1.data.length);
            FilePart part2 = c.needFilePart(3, 1);
            fos.write(part2.data, 0, part2.data.length);
            FilePart part3 = c.needFilePart(3, 2);
            fos.write(part3.data, 0, part3.data.length);
            fos.close();
            System.out.println("Ghi file thanh cong");
            
            //Sum c = (Sum) registry.lookup("Sum");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
